/**
 * 返回年月日
 * @export
 * @param {Date} date
 * @param {string} [splitor='']
 * @returns
 */
export function getDate(date: Date, splitor = ''): string {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return `${year}${splitor}${addZeroPrefix(month)}${splitor}${addZeroPrefix(day)}`;
}

/**
 * 返回年月日
 * @export
 * @param {Date} date
 * @returns
 */
export function getFormatDate(date: Date): string {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return `${year}年${addZeroPrefix(month)}月${addZeroPrefix(day)}日`;
}

/**
 * 返回年月
 * @export
 * @param {Date} date
 * @returns
 */
export function getMonth(date: Date): string {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  return `${year}${addZeroPrefix(month)}`;
}

/**
 * 返回时分秒/时分
 * @export
 * @param {*} date
 * @param {boolean} [withSecond=false]
 * @returns
 */
export function getTime(date: Date, withSecond = false): string {
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();
  return withSecond ? `${addZeroPrefix(hour)}:${addZeroPrefix(minute)}:${addZeroPrefix(second)}` : `${addZeroPrefix(hour)}:${addZeroPrefix(minute)}`;
}

export function getFullDate(date: Date) {
  return `${getFormatDate(date)} ${getTime(date)}`;
}

export function isToday(date: Date): boolean {
  return date.toDateString() === new Date().toDateString();
}

/**
 * 个位数，加0前缀
 * @param {*} number
 * @returns
 */
function addZeroPrefix(num: number): string | number {
  return num < 10 ? `0${num}` : num;
}
